package cn.zucc.edu.handyzucc.service.impl;

import cn.zucc.edu.handyzucc.dao.CommentDao;
import cn.zucc.edu.handyzucc.dao.ShopDao;
import cn.zucc.edu.handyzucc.entity.Shop;
import cn.zucc.edu.handyzucc.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopServiceImpl implements ShopService {
    @Autowired
    private ShopDao shopDao;
    @Autowired
    private CommentDao commentDao;

    @Override
    public List<Shop> getShopsByType(String shop_type) {
        return shopDao.getShopsByType(shop_type);
    }

    @Override
    public Shop getShopDetail(Integer shop_id) {
        return shopDao.getShopDetail(shop_id);
    }

    @Override
    public boolean updateShopRating(Integer shop_id, Integer shop_rating, Integer step) {
        return shopDao.updateShopRating(shop_id, shop_rating, step) == 1;
    }

    @Override
    public List<Shop> getAllShop() {
        return shopDao.getAllShop();
    }

    @Override
    public boolean deleteShop(Integer shop_id) {
        return shopDao.deleteShop(shop_id) == 1 && commentDao.deleteShopAllComment(shop_id) == 1;
    }

    @Override
    public int addShop(Shop shop) {
        shopDao.addShop(shop);
        return shop.getShop_id();
    }

    @Override
    public boolean updateShop(Shop shop) {
        return shopDao.updateShop(shop) == 1;
    }
}
